set_filenames(array("body" => "photo_edit.html")); include_once ("class/photos.class.php"); $photos = new Photos(); if(isset($_POST['upload'])) { //Check valid posting $ok = 1; if (!isset($_POST["photo_title"])|| strlen($_POST["photo_title"])<0) { $photo_title_alert = " Photo title missing"; $ok = 0; }else $photo_title_alert = ""; if (!isset($_POST["photo_license"])|| strlen($_POST["photo_license"])<0) { $photo_license_alert = " Missing"; $ok = 0; }else $photo_license_alert = ""; if (!isset($_POST["resolution"])|| strlen($_POST["resolution"])<0) { $resolution_alert = " Missing"; $ok = 0; }else $resolution_alert = ""; if (is_uploaded_file($_FILES["uploadfile"]["tmp_name"])) { /*if ($_FILES["uploadfile"]["size"]>=$site_config->free_max_filesize) { $inform = "File is too big. You should upload file has size less than ".$site_config->free_max_filesize; }else*/ if (strrpos($_FILES["uploadfile"]["type"],"image/") === false) { $upload_alert = "Warning: Invalid Image file was uploaded! Data was saved successful without updating image url."; $ok = 0; }else if ($ok == 1) //Upload file { $upload_time = time(); $file_tail = substr($_FILES["uploadfile"]["name"],strrpos($_FILES["uploadfile"]["name"],".")); //Make directory system if (!is_dir("upload")) { mkdir("upload", 0755); copy("_index.html", "upload/index.html"); } $normal_path = "upload/".$_SESSION["suserid"]; if (!is_dir($normal_path)) { mkdir($normal_path, 0755); copy("_index.html", $normal_path."/index.html"); } $o_path = "upload/".$_SESSION["suserid"]."/".generatePassword(4); if (!is_dir($o_path)) { mkdir($o_path, 0755); copy("_index.html", $o_path."/index.html"); } $new_path = $o_path."/".generatePassword(8).$file_tail; //Upload original file first if (move_uploaded_file($_FILES["uploadfile"]["tmp_name"], $new_path)) { $imageInfo = getimagesize($new_path); $width = $imageInfo[0]; $height = $imageInfo[1]; $thmbfilename = $normal_path."/".$upload_time."_thmb".$file_tail; $new_w = ($width<$clsSite_config->thumb_size)?$width:$clsSite_config->thumb_size; $new_h = (double) $new_w*($height/$width); createthumb($new_path,$thmbfilename,$new_w,$new_h); $tmpfilename = $normal_path."/".$upload_time."_tmp".$file_tail; $new_w = ($width<$clsSite_config->sample_size)?$width:$clsSite_config->sample_size; $new_h = (double) $new_w*($height/$width); createthumb($new_path,$tmpfilename,$new_w,$new_h); $wtmfilename = $normal_path."/".$upload_time."_wtm".$file_tail; watermark($tmpfilename, $wtmfilename, WATERMARK, WTM_QUALITY); //Xoa file temp unlink($tmpfilename); if (isset($_POST["photo_sid"]) && $_POST["photo_sid"] != "") { //Update database $photo_sid = $photos->UpdateCommonInfo($_POST["photo_sid"], $_POST["photo_title"], $_POST["photo_des"], $_POST["photo_license"], $_POST["category"], $_POST["resolution"]); $photo_sid = $photos->UpdatePhotos($photo_sid, $_FILES["uploadfile"]["type"], $_FILES["uploadfile"]["size"],$width, $height, $thmbfilename, $wtmfilename, $new_path); }else { //Insert to database $photo_sid = $photos->InsertPhotos($_POST["photo_title"], $upload_time, $_POST["photo_des"], $_POST["photo_license"], $_POST["category"], $_FILES["uploadfile"]["type"], $_FILES["uploadfile"]["size"], $_POST["resolution"], $width, $height, $_SESSION["suserid"], DatetimeFormat($upload_time), $thmbfilename, $wtmfilename, $new_path, 0); } $frmSubmit = "m_uploads.php"; $titleCom = "Finish upload"; $confirmMess = "Congratulation! Your file is uploaded successfully! Now you can management your own files"; include("confirm.php"); die; }else { $error = "Image cannot be moved for some reason, no action occur!!!"; $upload_alert = ""; $ok = 0; } } } else { if (isset($_POST["photo_sid"]) && $_POST["photo_sid"] != "") {//Update database - without image $photo_sid = $photos->UpdateCommonInfo($_POST["photo_sid"], $_POST["photo_title"], $_POST["photo_des"], $_POST["category"], $_POST["resolution"]); $frmSubmit = "m_uploads.php"; $titleCom = "Finish editing"; $confirmMess = "Congratulation! Your file is updated without change of photo successfull!"; include("confirm.php"); }else { $error = "No file upload?"; $upload_alert = ""; $ok = 0; } } if ($ok == 0) { $template->assign_vars(array( "ERROR" => $error, "PHOTO_TITLE" => $_POST["photo_title"], "PHOTO_SID" => $_REQUEST["photo_sid"], "PHOTO_TITLE_ALERT" => $photo_title_alert, "CATEGORY_ALERT" => $category_alert, "UPLOAD_ALERT" => $upload_alert, "PHOTO_LICENSE" => $photo_license, "PHOTO_LICENSE_ALERT" => $photo_license_alert, "RESOLUTION0" => $_POST["resolution"]=="Web resolution"?"selected":"", "RESOLUTION1" => $_POST["resolution"]=="Print resolution"?"selected":"", "RESOLUTION2" => $_POST["resolution"]=="Additional format (vector, RAW etc. - if available)"?"selected":"", "RESOLUTION_ALERT" => $resolution_alert, "PHOTO_DES" => $_POST["photo_des"] )); $cat_sid = $_POST["cat_sid"]; } }else if (isset($_REQUEST["photo_sid"]) && $photo_info = mysql_fetch_array($photos->GetBySId($_REQUEST["photo_sid"]))) { if ($photo_info["photo_designer"] != $_SESSION["suserid"]) { $frmSubmit = "photo_upload.php"; $titleCom = "Hacking attemp!"; $confirmMess = "Sorry, you can not edit the file that is not belong to you!"; include("confirm.php"); die; } $template->assign_vars(array( "PHOTO_TITLE" => $photo_info["photo_title"], "PHOTO_SID" => $_REQUEST["photo_sid"], "PHOTO_PREVIEW" => "", "RESOLUTION0" => $photo_info["resolution"]=="Web resolution"?"selected":"", "RESOLUTION1" => $photo_info["resolution"]=="Print resolution"?"selected":"", "RESOLUTION2" => $photo_info["resolution"]=="Additional format (vector, RAW etc. - if available)"?"selected":"", "PHOTO_DES" => $photo_info["photo_des"] )); $cat_sid = $photo_info["category"]; } $result = $cats->GetRootCat(); while ($row = mysql_fetch_array($result)) { $template->assign_block_vars("catselect",array( "CAT_SID" => $row["cat_sid"], "CAT_NAME" => $row["cat_name"], "SELECTED" => $row["cat_sid"] == $cat_id?" selected ":"" )); $result1 = $cats->GetChildCat($row["cat_sid"]); while ($row1 = mysql_fetch_array($result1)) { $template->assign_block_vars("catselect",array( "CAT_SID" => $row1["cat_sid"], "CAT_NAME" => $row["cat_name"]." -- ".$row1["cat_name"], "SELECTED" => $row1["cat_sid"] == $cat_sid?" selected ":"" )); } } $template->pparse("body"); include("footer.php"); ?>